﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using AJArt.Mvc.Models;
using System.Text;

namespace AJArt.Mvc.Controllers
{
    public class CategoryController : Controller
    {
        public ICategoryService CategoryService
        {
            get;
            set;
        }

        protected override void Initialize(RequestContext requestContext)
        {
            if (CategoryService == null)
            {
                CategoryService = new CategoryService();
            }

            base.Initialize(requestContext);
        }

        public ActionResult Index(string id)
        {
            if (id == null)
                //return RedirectToAction("Index", new { id = "advertising" });
                return Redirect("~/category/advertising/");

            ViewBag.Title = Capitalize(id) + " - A.J ART";
            ViewBag.CssClass = id;
            ViewBag.Stories = CategoryService.GetStories(id);


            return View();
        }

        private string Capitalize(string buffer)
        {
            if (String.IsNullOrEmpty(buffer))
                return buffer;
            StringBuilder sb = new StringBuilder(buffer);
            sb[0] = sb[0].ToString().ToUpper()[0];
            return sb.ToString();
        }

        public new ActionResult View(string id, string story)
        {
            ViewBag.Title = Capitalize(id) + " - A.J ART";
            ViewBag.CssClass = id;
            ViewBag.Story = CategoryService.GetStoryDetail(id, story);
            return View();
        }
    }
}
